<?php
namespace app\common\entity;

use think\Db;
use think\Model;

class UserAddress extends Model
{
    protected $table = 'user_address';

    // 状态
    public function getStatus()
    {
        switch ($this->status) {
            case 0:
                return '常用';
            case 1:
                return '默认地址';
            default:
                return '';
        }
    }

    // 编辑收获地址
    public function updateRess($query,$data)
    {
        if(isset($data['status'])){
            $query->status = $data['status'];
        }
        if(isset($data['mobile'])){
            $query->mobile = $data['mobile'];
        }
        if(isset($data['user_name'])){
            $query->user_name = $data['user_name'];
        }
        if(isset($data['area'])){
            $query->area = $data['area'];
        }
        if(isset($data['address_detail'])){
            $query->address_detail = $data['address_detail'];
        }
        return $query->save();
    }
    // 添加地址
    public function addRess($query,$data,$uid)
    {
        $query->uid = $uid;
        if(isset($data['status'])) {
            $query->status = $data['status'];
        }
        $query->mobile = $data['mobile'];
        $query->user_name = $data['user_name'];
        $query->address_detail = $data['address_detail'];
        $query->create_time = time();
        $query->area = $data['area'];
        $query->save();
        return $query->getLastInsID();
    }


}
